package com.ggh.jinjilive.ui.mine.members.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemAddressBinding;
import com.ggh.jinjilive.databinding.ItemMembersBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.mall.goods.thegoods.TheGoodsAddressMobile;
import com.ggh.jinjilive.mobile.mine.MembersMobile;

import java.util.List;

public class MembersAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private List<MembersMobile> membersMobileList;

    public void setAdd(List<MembersMobile> membersMobileList) {
        this.membersMobileList = membersMobileList;
        notifyDataSetChanged();
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemMembersBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_members, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        MembersMobile membersMobile = membersMobileList.get(position);
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        if(null != membersMobile){
            holder.binding.tvMonth.setText(membersMobile.getMonth() + "个月");
            holder.binding.tvPrice.setText("￥" + membersMobile.getPrice());
            holder.binding.tvType.setText(membersMobile.getType());
            if(membersMobile.isPitchOn()){
                holder.binding.llVip.setBackgroundResource(R.drawable.bg_1_5_0080ff);
                holder.binding.tvMonth.setTextColor(Color.parseColor("#0080ff"));
                holder.binding.tvPrice.setTextColor(Color.parseColor("#0080ff"));
                holder.binding.tvType.setTextColor(Color.parseColor("#0080ff"));
            }else {
                holder.binding.llVip.setBackgroundResource(R.drawable.bg_1_5_f);
                holder.binding.tvMonth.setTextColor(Color.parseColor("#FFFFFF"));
                holder.binding.tvPrice.setTextColor(Color.parseColor("#FFFFFF"));
                holder.binding.tvType.setTextColor(Color.parseColor("#FFFFFF"));
            }
            holder.binding.llVip.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,membersMobile);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == membersMobileList ? 0 : membersMobileList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemMembersBinding binding;
        public ItemViewHolder(@NonNull ItemMembersBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}